﻿using Application.AppService.SSAppServoice;
using AutoMapper;
using Domain;
using EFCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace UI.Controllers.Pay_Scale_Management_薪酬标准管理_
{
    public class PayInquiryController : Controller
    {
        private readonly ISSAppService ssAppServoice;
        private readonly IMapper mapper;
        private readonly IMemoryCache memCache;

        public PayInquiryController(ISSAppService ssAppServoice, IMapper mapper, IMemoryCache memCache)
        {
            this.ssAppServoice = ssAppServoice;
            this.mapper = mapper;
            this.memCache = memCache;
        }
        /// <summary>
        /// 薪酬查询
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 查询显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Index1()
        {
            return View();
        }

        [HttpPost("TJFYSS")]
        public IActionResult TJFYSS(string StandardId, string gzc, DateTime startDate, DateTime endDate, int page, int pageSize, string ChangeStatus)
        {
            string cacheId = "TJFYSS" + StandardId;
            SSFenYE sSFenYE = memCache.Get(cacheId) as SSFenYE;
            if (sSFenYE == null)
            {
                 sSFenYE = ssAppServoice.DateSSAsync(StandardId, gzc, startDate, endDate, page, pageSize, ChangeStatus);

                //5秒后失效
                memCache.Set(cacheId, sSFenYE, new TimeSpan(0, 0, 5));
            }
            else
            {
                Console.WriteLine("从缓存获取");
            } 
            return Json(sSFenYE);
        }
    }
}
